#pragma warning(disable: 4996)
#pragma warning(disable: 6031)
#pragma warning(disable: 6328)
#pragma warning(disable: 4477)

#include <stdio.h>

typedef unsigned long uint4;
typedef unsigned long long uint8;

union LongNumber {
	uint8 i8;
	uint4 i4[2];
};

static const int ENSize = 8;
typedef struct ExactNumber* PtrToExactNumber;
typedef struct ExactNumber {
	char sign;
	uint4 i1[ENSize];
	long coef;
}ExactNumber;

ExactNumber en_product(PtrToExactNumber a, uint4 b) {
	ExactNumber res = {1};
	LongNumber temp = {0};
	uint8 _b = (uint8)b;
	LongNumber lo = { 0 };
	LongNumber hi = { 0 };
	for (int i = 0; i < ENSize; i++) {
		temp.i8 = a->i1[i] * _b;
		if (temp.i8 == 0)
			continue;
		if (i > 0) {
			lo.i8 = uint8(temp.i4[0]) + res.i1[i];
			res.i1[i] = lo.i4[0];
			hi.i8 = uint8(res.i1[i + 1]) + lo.i4[1];
			res.i1[i + 1] = hi.i4[0];
			if(hi.i4[1]>0)
				res.i1[i + 2] = hi.i4[1];
		}
		else {
			res.i1[0] = temp.i4[0];
			res.i1[1] = temp.i4[1];
		}
	}

	return res;
}

ExactNumber en_product(PtrToExactNumber a, PtrToExactNumber b) {
	ExactNumber res = {1};
	LongNumber temp;
	temp.i8 = 0;

	return res;
}


union MyNumber {
	uint4 i4;
	unsigned char b[4];
};

// _190718_union
int main_190718_union()
{
	LongNumber a = { 123456789 };
	printf("sizeof(LongNumber) = %d\n", sizeof(LongNumber));
	printf("sizeof(int) = %d\n", sizeof(int));
	printf("sizeof(long long) = %d", sizeof(long long));
	MyNumber b = { 0xffffffff };
	b.i4 -= 1;

	ExactNumber n1 = { 1,1 };
	ExactNumber n2 = en_product(&n1, 123456789);
	n2 = en_product(&n2, 123456789);
	a.i4[0] = n2.i1[0];
	a.i4[1] = n2.i1[1];
	char c0 = 9;
	char c1 = 9;
	char c2 = c0 * c1;
	return 0;
}